from sentence_transformers import SentenceTransformer
import env_test

# 指定该模型在本地的缓存路径
model = SentenceTransformer(
	"E:/ai/models/RAG/bge-large-zh-v1.5"	
)

device = env_test.get_device(False)
print(device)

model.to(device)

def encode(sentences):
    embeddings = model.encode(sentences, normalize_embeddings=True)
    return embeddings

# 测试一次调用
def test_embeddings():
    sentences = ["中国的首都是北京"]
    embeddings = encode(sentences)
    print(embeddings)

# 循环测试调用
def test_in_dead_loop():
    while True:
        test_embeddings()